| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | Static Public Member Functions | List of all members
nkMemory::Buffer Class Referencefinal

A buffer holding binary data. More...

## Public Member Functions
| Buffer () noexcept
| Buffer (unsigned long long size) noexcept
| Buffer (const unsigned char *data, unsigned long long size) noexcept
| Buffer (std::initializer_list< unsigned char > args) noexcept
| Buffer (const Buffer &other) noexcept
| Buffer (Buffer &&other) noexcept
| ~Buffer ()
unsigned char * | getData () const
unsigned long long | getSize () const
bool | empty () const
unsigned char & | front ()
const unsigned char & | front () const
unsigned char & | back ()
const unsigned char & | back () const
unsigned char * | begin ()
const unsigned char * | begin () const
unsigned char * | end ()
const unsigned char * | end () const
Buffer & | clear ()
Buffer & | resize (unsigned long long size)
Buffer & | append (unsigned char value)
Buffer & | erase (unsigned long long index, unsigned long long count=1ull)
BufferDataDescriptor | relinquishDataOwnership ()
unsigned char & | operator[] (unsigned long long index)
const unsigned char & | operator[] (unsigned long long index) const
Buffer & | operator= (const Buffer &other) noexcept
Buffer & | operator= (Buffer &&other) noexcept
template<typename T , std::size_t S>
| Buffer (const std::array< T, S > &array) noexcept
template<typename T >
| Buffer (const std::vector< T > &vec) noexcept

## Static Public Member Functions
static Buffer | createAndTakeMemory (unsigned char *data, unsigned long long size)

## Detailed Description

A buffer holding binary data.

The Buffer class owns its memory, and is hard coded to handle binary data shaped as unsigned char. It is meant to manage all memory and operations in the DLL itself, meaning that passing one from user space to dll space is safe. This class will be the basis to safely exchange data with components. It avoids having to play with vectors that can be unsafe due to their build time template parameters.

If you need something else than unsigned char, take a look at the BufferCast template class. Its purpose is to use this class, with an API casting for you. For data that doesn't need to be copied, BufferView can be the answer as it is only meant to offer a bridge to the data.

## Constructor & Destructor Documentation

## ◆ Buffer() [1/8]

nkMemory::Buffer::Buffer | ( |  | ) |
| noexcept

Default constructor. The buffer will be empty.

## ◆ Buffer() [2/8]

nkMemory::Buffer::Buffer | ( | unsigned long long | size | ) |
| noexcept

Size constructor. Will allocate the size requested within the buffer. Memory will be 0-cleared.

Parameters

  size | The size of the buffer to create. As this buffer is binary, size is in bytes.

## ◆ Buffer() [3/8]

nkMemory::Buffer::Buffer | ( | const unsigned char * | data,
|  | unsigned long long | size
| ) |  |
| noexcept

Data constructor. Will copy the data into its internal memory.

Parameters

  data | Pointer to the data to copy.
  size | The size of the data to copy, in bytes.

## ◆ Buffer() [4/8]

nkMemory::Buffer::Buffer | ( | std::initializer_list< unsigned char > | args | ) |
| noexcept

Utility initializer list constructor.

Parameters

  args | The list of elements to initialize the buffer with.

## ◆ Buffer() [5/8]

nkMemory::Buffer::Buffer | ( | const Buffer & | other | ) |
| noexcept

Copy constructor. Will duplicate the data.

Parameters

  other | The buffer to copy.

## ◆ Buffer() [6/8]

nkMemory::Buffer::Buffer | ( | Buffer && | other | ) |
| noexcept

Move constructor. Data will be moved into the buffer being constructed.

Parameters

  other | The buffer to move.

## ◆ ~Buffer()

nkMemory::Buffer::~Buffer | ( |  | ) |

Destructor. The destructor frees the memory, invalidating all potential pointers to it.

## ◆ Buffer() [7/8]

template<typename T , std::size_t S>

nkMemory::Buffer::Buffer | ( | const std::array< T, S > & | array | ) |
| noexcept

Utility copy constructor with arrays.

Parameters

  array | The array to copy from.

## ◆ Buffer() [8/8]

template<typename T >

nkMemory::Buffer::Buffer | ( | const std::vector< T > & | vec | ) |
| noexcept

Utility copy constructor with vectors.

Parameters

  vec | The vector to copy from.

## Member Function Documentation

## ◆ getData()

unsigned char* nkMemory::Buffer::getData | ( |  | ) | const

Returns
  The pointer over the internal data.

## ◆ getSize()

unsigned long long nkMemory::Buffer::getSize | ( |  | ) | const

Returns
  The size of the buffer, in bytes.

## ◆ empty()

bool nkMemory::Buffer::empty | ( |  | ) | const

Returns
  Whether the buffer is empty (true) or not (false). An empty buffer has a size of 0.

## ◆ front() [1/2]

unsigned char& nkMemory::Buffer::front | ( |  | ) |

Returns
  A reference over the first element of the buffer.

## ◆ front() [2/2]

const unsigned char& nkMemory::Buffer::front | ( |  | ) | const

Returns
  A reference over the first element of the buffer.

## ◆ back() [1/2]

unsigned char& nkMemory::Buffer::back | ( |  | ) |

Returns
  A reference over the last element of the buffer.

## ◆ back() [2/2]

const unsigned char& nkMemory::Buffer::back | ( |  | ) | const

Returns
  A reference over the last element of the buffer.

## ◆ begin() [1/2]

unsigned char* nkMemory::Buffer::begin | ( |  | ) |

Returns
  A pointer over the beginning of the memory spot.

## ◆ begin() [2/2]

const unsigned char* nkMemory::Buffer::begin | ( |  | ) | const

Returns
  A pointer over the beginning of the memory spot.

## ◆ end() [1/2]

unsigned char* nkMemory::Buffer::end | ( |  | ) |

Returns
  A pointer right past the end of the memory spot.

## ◆ end() [2/2]

const unsigned char* nkMemory::Buffer::end | ( |  | ) | const

Returns
  A pointer right past the end of the memory spot.

## ◆ clear()

Buffer& nkMemory::Buffer::clear | ( |  | ) |

Clears the buffer, freeing its internal memory and resetting it to its empty state.

Returns
  A reference over the buffer.

## ◆ resize()

Buffer& nkMemory::Buffer::resize | ( | unsigned long long | size | ) |

Resizes the buffer for it to fit a given size. This will trigger a reallocation of the data. In the process, the buffer will copy its content to the new memory area.

Parameters

  size | The size to fit, in bytes.

Returns
  A reference over the buffer.

## ◆ append()

Buffer& nkMemory::Buffer::append | ( | unsigned char | value | ) |

Appends a byte to the buffer. This will cause the buffer to reallocate and copy data around.

Parameters

  value | The value of the byte to append.

Returns
  A reference over the buffer.

## ◆ erase()

Buffer& nkMemory::Buffer::erase | ( | unsigned long long | index,
|  | unsigned long long | count = `1ull`
| ) |  |

Erases bytes from the buffer. This will cause the buffer to reallocate and copy remaining data around.

Parameters

  index | The starting index to erase data from.
  count | The number of bytes to erase.

Returns
  A reference over the buffer.

## ◆ relinquishDataOwnership()

BufferDataDescriptor nkMemory::Buffer::relinquishDataOwnership | ( |  | ) |

Requests a buffer to abandon its ownership, leaving the management to the client using this function.

Returns
  The information about the memory that was held by the buffer.

Remarks
  Data has to be freed the way it has been allocated. Currently, memory is allocated using the default new[] allocator, needing the delete[] counterpart.

## ◆ operator[]() [1/2]

unsigned char& nkMemory::Buffer::operator[] | ( | unsigned long long | index | ) |

Indexing operator.

Parameters

  index | The index of the element to index in the memory.

Returns
  A reference over requested element.

## ◆ operator[]() [2/2]

const unsigned char& nkMemory::Buffer::operator[] | ( | unsigned long long | index | ) | const

Indexing operator, const versioned.

Parameters

  index | The index of the element to index in the memory.

Returns
  A reference over requested element.

## ◆ operator=() [1/2]

Buffer& nkMemory::Buffer::operator= | ( | const Buffer & | other | ) |
| noexcept

Copy assignment operator.

Parameters

  other | The buffer to copy.

Returns
  A reference over calling buffer, once updated.

## ◆ operator=() [2/2]

Buffer& nkMemory::Buffer::operator= | ( | Buffer && | other | ) |
| noexcept

Move assignment operator.

Parameters

  other | The buffer to move.

Returns
  A reference over calling buffer, once updated.

## ◆ createAndTakeMemory()

static Buffer nkMemory::Buffer::createAndTakeMemory | ( | unsigned char * | data,
|  | unsigned long long | size
| ) |  |
| static

Static creation function for which the buffer takes ownership of the memory provided. This means the buffer will free the memory given once it is destroyed (through the operator delete[]).

Parameters

  data | The data the buffer will free.
  size | The size, in bytes, of the data provided.

Remarks
  This function will cause the memory to cross the dll-boundary (created by client code, deleted by dll code). As such, it should be used with care and is intended to be used in edge cases mostly. Prefer to create a BufferView over the memory region and manage its lifetime in the client code, if possible.

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsMemory/Containers/Buffer.h